package cn.gson.crm.controller;

import cn.gson.crm.model.mapper.WorkMapper;
import cn.gson.crm.model.pojos.Employee;
import cn.gson.crm.model.pojos.Work;
import cn.gson.crm.model.service.WorkService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Work")
public class WorkContract {
    @Autowired
    WorkService workService;
    @Autowired
    WorkMapper workMapper;
    //查询
    @RequestMapping("/select1")
    @ResponseBody
    public Map<String,Object> select1(Integer currentPage, Integer pageSize,String min){
        Page<Object> obj= PageHelper.startPage(currentPage,pageSize);
        List<Work> workList= workService.select1(min);
        Map<String,Object> map=new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("row",workList);
        return map;
    }
    //新增
    @RequestMapping("/addWork")
    @ResponseBody
    public void addWork(@RequestBody Work work){
        System.out.println(work.getWorkName());
        work.setWorkName(work.getEmployeeByYgId().getYname());
        workService.addWork(work);
    }
    //新增
    @RequestMapping("/selectEmployee2")
    @ResponseBody
    public List<Employee> selectEmployee(){ return workService.selectEmployee();}

    @RequestMapping("/worktu")
    @ResponseBody
    public Map<String,Object> sellType(String vv){
        Map<String,Object> map = null;
        if(vv.equals("日志类型分布")) {
            map = workService.selectWork();
        }
        else{
            map = workService.selectWork2();
        }
        return map;

    }
}
